﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using Etong.Web;
/// <summary>
///AfterFactory 的摘要说明
/// </summary>
public class AfterFactory
{
    public static IAfterDoing GetAfter(string className)
    {
        try
        {
            return (IAfterDoing)Assembly.Load("App_Code").CreateInstance(className);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public static IAfterDoing GetAfter(ConfigTable cTab, AfterType afType)
    {
        IAfterDoing afDoing = null;
        switch (afType)
        {
            case AfterType.AfterInsert:
                afDoing= GetAfter(cTab.AfterInsertClassName);
                break;
            case AfterType.AfterUpdate:
                afDoing = GetAfter(cTab.AfterUpdateClassName);
                break;
            case AfterType.AfterDelete:
                afDoing = GetAfter(cTab.AfterDeleteClassName);
                break;
        }
        return afDoing;
    }

    public static void AfterDo(ConfigTable cTab, AfterType afType,string PKValue)
    {
        IAfterDoing afDoing = GetAfter(cTab, afType);
        if (afDoing != null)
        {
            switch (afType)
            {
                case AfterType.AfterInsert:
                    afDoing.AfterInsert();
                    break;
                case AfterType.AfterUpdate:
                    afDoing.AfterUpdate(PKValue);
                    break;
                case AfterType.AfterDelete:
                    afDoing.AfterDelete(PKValue);
                    break;
            }
        }
    }
}
